﻿function showLineChart(objName, data, title, categoryField, valueFields, parseDates, minPeriod, timeFormat, colorSchema)
{
	// SERIAL CHART
	var chart = new AmCharts.AmSerialChart1();
	chart.pathToImages = "../../resources/chart/images/";
	chart.dataProvider = data;
	chart.marginLeft = 10;
	chart.startDuration = 0.5;  
	chart.categoryField = categoryField;
	/*
	 * chart.zoomOutButton = { backgroundColor: '#000000', backgroundAlpha: 0.15 };
	 */
	chart.fontSize = 13;  
    chart.fontFamily = "微软雅黑"; 

	// AXES
	// category
	var categoryAxis = chart.categoryAxis;
	categoryAxis.parseDates = parseDates;
	if (minPeriod) categoryAxis.minPeriod = minPeriod;
	categoryAxis.dashLength = 1;  
    categoryAxis.gridAlpha = 0;  
    categoryAxis.labelRotation = 18;  
    categoryAxis.axisColor = "#000000"; 

	// 坐标轴-Y轴
    var valueAxis = new AmCharts.ValueAxis();  
    valueAxis.axisColor = "#DADADA";  
    valueAxis.dashLength = 1;  
    valueAxis.title="数 量";
    valueAxis.logarithmic = false;   
    chart.addValueAxis(valueAxis);  
	
	var lineColors = colorSchema ? colorSchema : ["#2ec7c9", "#b6a2de", "#65815d", "#dd8800", "#dd00dd"];
	var negativeLineColors = ["#637bb6", ];
	// GRAPH
	for (var i=0; i<valueFields.length; ++i)
	{
		graph = new AmCharts.AmGraph();
		graph.type = "smoothedLine"; // this line makes the graph smoothed
										// line.
		graph.lineColor = lineColors[i % lineColors.length];
		graph.negativeLineColor = negativeLineColors[i % negativeLineColors.length]; 
		graph.title = title[i];
		graph.bullet = "round";
		graph.bulletSize = 5;
		graph.lineThickness = 2;
		graph.valueField = valueFields[i];
		graph.bulletColor = "#FFFFFF";  
        graph.bulletBorderColor = "#00BBCC";  
        graph.bulletBorderThickness = 1; 
        graph.balloonText = title[i]+":[["+valueFields[i]+"]]";  
		chart.addGraph(graph);
	}         
	
	var chartCursor = new AmCharts.ChartCursor();  
    chartCursor.cursorPosition = "middle";  
    chartCursor.cursorColor = "#D40600";  
    chartCursor.bulletSize = 8;  
    chart.addChartCursor(chartCursor); 

	// SCROLLBAR
	var chartScrollbar = new AmCharts.ChartScrollbar();
	chartScrollbar.graph = graph;
	chartScrollbar.backgroundColor = "#DDDDDD";
	chartScrollbar.scrollbarHeight = 30;
	chartScrollbar.selectedBackgroundColor = "#FFFFFF";
	chart.addChartScrollbar(chartScrollbar);

	 var legend = new AmCharts.AmLegend();
     legend.markerType = "circle"; 
     legend.useGraphSettings = true;
     legend.valueWidth = 20;
     legend.equalWidths = false; 
     chart.addLegend(legend);
	// WRITE
	chart.write(objName);
}

function showLineChartPercent(objName, data, title, categoryField, valueFields, parseDates, minPeriod, timeFormat, colorSchema)
{
	// SERIAL CHART
	var chart = new AmCharts.AmSerialChart1();
	chart.pathToImages = "../../resources/chart/images/";
	chart.dataProvider = data;
	chart.marginLeft = 10;
	chart.startDuration = 0.5;  
	chart.categoryField = categoryField;
	/*
	 * chart.zoomOutButton = { backgroundColor: '#000000', backgroundAlpha: 0.15 };
	 */
	chart.fontSize = 13;  
    chart.fontFamily = "微软雅黑"; 

	// AXES
	// 横坐标
	var categoryAxis = chart.categoryAxis;
	categoryAxis.parseDates = parseDates;
	if (minPeriod) categoryAxis.minPeriod = minPeriod;
	categoryAxis.dashLength = 1;  
    categoryAxis.gridAlpha = 0;  
    categoryAxis.labelRotation = 18;  
    categoryAxis.axisColor = "#000000"; 

	// 坐标轴-Y轴
    var valueAxis = new AmCharts.ValueAxis();  
    valueAxis.unit="%";
    valueAxis.axisColor = "#DADADA";  
    valueAxis.dashLength = 1;  
    valueAxis.title="数 量";
    valueAxis.logarithmic = false;   
    chart.addValueAxis(valueAxis);  
	
	var lineColors = colorSchema ? colorSchema : ["#2ec7c9", "#b6a2de", "#65815d", "#dd8800", "#dd00dd"];
	var negativeLineColors = ["#637bb6", ];
	// GRAPH
	for (var i=0; i<valueFields.length; ++i)
	{
		graph = new AmCharts.AmGraph();
		graph.type = "smoothedLine"; // this line makes the graph smoothed
										// line.
		graph.lineColor = lineColors[i % lineColors.length];
		graph.negativeLineColor = negativeLineColors[i % negativeLineColors.length];
		graph.title = title[i];
		graph.bullet = "round";
		graph.bulletSize = 5;
		graph.lineThickness = 2;
		graph.valueField = valueFields[i];
		graph.bulletColor = "#FFFFFF";  
        graph.bulletBorderColor = "#00BBCC";  
        graph.bulletBorderThickness = 1; 
        graph.balloonText = title[i]+":[["+valueFields[i]+"]]%";  
		chart.addGraph(graph);
	}         
	
	var chartCursor = new AmCharts.ChartCursor();  
    chartCursor.cursorPosition = "middle";  
    chartCursor.cursorColor = "#D40600";  
    chartCursor.bulletSize = 8;  
    chartCursor.cursorAlpha = 0;
    chart.addChartCursor(chartCursor); 

	// SCROLLBAR
	var chartScrollbar = new AmCharts.ChartScrollbar();
	chartScrollbar.graph = graph;
	chartScrollbar.backgroundColor = "#DDDDDD";
	chartScrollbar.scrollbarHeight = 30;
	chartScrollbar.selectedBackgroundColor = "#FFFFFF";
	chart.addChartScrollbar(chartScrollbar);

	 var legend = new AmCharts.AmLegend();
     legend.markerType = "circle"; 
     legend.useGraphSettings = true;
     legend.valueWidth = 20;
     legend.equalWidths = false; 
     chart.addLegend(legend);
	// WRITE
	chart.write(objName);
}

function showPieChart1(objName, data, title, categoryField, valueFields, parseDates, minPeriod, timeFormat)
{
	// PIE CHART
	chart = new AmCharts.AmPieChart();

	// title of the chart
	chart.addTitle(title, 16);

	chart.dataProvider = data;
	chart.titleField = categoryField;
	chart.valueField = valueFields[0];
	chart.sequencedAnimation = true;
	chart.startEffect = "elastic";
	chart.innerRadius = "30%";
	chart.startDuration = 2;
	chart.labelRadius = 15;

	// the following two lines makes the chart 3D
	chart.depth3D = 10;
	chart.angle = 15;
	
	// LEGEND
	 var legend = new AmCharts.AmLegend();
     legend.markerType = "circle"; 
     legend.useGraphSettings = true;
     legend.valueWidth = 20;
     legend.equalWidths = false; 
     chart.addLegend(legend);
    /*
	 * legend = new AmCharts.AmLegend(); legend.align = "center";
	 * legend.markerType = "circle"; chart.balloonText = "[[title]]<br><span
	 * style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>";
	 * chart.addLegend(legend);
	 */

	// WRITE
	chart.write(objName);
}
function showPieChart2(objName, data, title, categoryField, valueFields, parseDates, minPeriod, timeFormat)
{
	// PIE CHART
	chart = new AmCharts.AmPieChart2();

	// title of the chart
	chart.addTitle(title, 16);

	chart.dataProvider = data;
	chart.titleField = categoryField;
	chart.valueField = valueFields[0];
	chart.sequencedAnimation = true;
	chart.startEffect = "elastic";
	chart.innerRadius = "30%";
	chart.startDuration = 2;
	chart.labelRadius = 15;

	// the following two lines makes the chart 3D
	chart.depth3D = 10;
	chart.angle = 15;

	// WRITE
	chart.write(objName);
}
function showPieChart3(objName, data, title, categoryField, valueFields, parseDates, minPeriod, timeFormat)
{
	// PIE CHART
	chart = new AmCharts.AmPieChart3();

	// title of the chart
	chart.addTitle(title, 16);

	chart.dataProvider = data;
	chart.titleField = categoryField;
	chart.valueField = valueFields[0];
	chart.sequencedAnimation = true;
	chart.startEffect = "elastic";
	chart.innerRadius = "30%";
	chart.startDuration = 2;
	chart.labelRadius = 15;

	// the following two lines makes the chart 3D
	chart.depth3D = 10;
	chart.angle = 15;

	// WRITE
	chart.write(objName);
}

function showColumn3DStacked(divName,data,text,column1,column2,columnTitle1,columnTitle2){
	 // SERIAL CHART
    chart = new AmCharts.AmSerialChart();
    chart.dataProvider = data;
    chart.categoryField = text;
    chart.color = "#000000";
    chart.fontSize = 14;
    chart.startDuration = 1;
    chart.plotAreaFillAlphas = 0.2;
    // the following two lines makes chart 3D
    chart.angle = 20;
    chart.depth3D = 30;

    // AXES
    // category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.gridAlpha = 0.2;
    categoryAxis.gridPosition = "start";
    categoryAxis.gridColor = "#000000";
    categoryAxis.axisColor = "#000000";
    categoryAxis.axisAlpha = 0.5;
    categoryAxis.dashLength = 5;

    // value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.stackType = "3d"; // This line makes chart 3D stacked (columns are placed one behind another)
    valueAxis.gridAlpha = 0.2;
    valueAxis.gridColor = "#000000";
    valueAxis.axisColor = "#000000";
    valueAxis.axisAlpha = 0.5;
    valueAxis.dashLength = 5;
    valueAxis.title = "数量";
    valueAxis.titleColor = "#000000";
    valueAxis.unit = "%";
    chart.addValueAxis(valueAxis);

    // GRAPHS
    // first graph
    var graph1 = new AmCharts.AmGraph();
    graph1.title = columnTitle1;
    graph1.valueField = column1;
    graph1.type = "column";
    graph1.lineAlpha = 0;
    graph1.lineColor = "#D2CB00";
    graph1.fillAlphas = 1;
    graph1.balloonText = "[[category]] ("+columnTitle1+"): <b>[[value]]</b>";
    chart.addGraph(graph1);

    // second graph
    var graph2 = new AmCharts.AmGraph();
    graph2.title = columnTitle2;
    graph2.valueField = column2;
    graph2.type = "column";
    graph2.lineAlpha = 0;
    graph2.lineColor = "#BEDF66";
    graph2.fillAlphas = 1;
    graph2.balloonText = "[[category]] ("+columnTitle2+"): <b>[[value]]</b>";
    chart.addGraph(graph2);

    chart.write(divName);
}

function showColumn3D(objName,data,xName){
	chart = new AmCharts.AmSerialChart();
    chart.dataProvider = data;
    chart.color = "#000000";
    chart.categoryField = xName;
    // the following two lines makes chart 3D
    chart.depth3D = 20;
    chart.angle = 30;
    // AXES
    // category
    var categoryAxis = chart.categoryAxis;
    //categoryAxis.labelRotation = 90;
    categoryAxis.dashLength = 5;
    categoryAxis.gridColor = "#000000";
    categoryAxis.gridPosition = "start";
    // value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.title = "Visitors";
    valueAxis.gridColor = "#000000";
    valueAxis.axisColor = "#000000";
    valueAxis.dashLength = 5;
    chart.addValueAxis(valueAxis);
    // GRAPH
    var graph = new AmCharts.AmGraph();
    graph.valueField = "visits";
    graph.colorField = "color";
    graph.balloonText = "<span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>";
    graph.type = "column";
    graph.lineAlpha = 0;
    graph.fillAlphas = 1;
    chart.addGraph(graph);
    // CURSOR
    var chartCursor = new AmCharts.ChartCursor();
    chartCursor.cursorAlpha = 0;
    chartCursor.zoomable = false;
    chartCursor.categoryBalloonEnabled = false;
    chart.addChartCursor(chartCursor);
    chart.creditsPosition = "top-right";
    // WRITE
    chart.write(objName);
}

function columnCylinders(objId,data){
	chart = new AmCharts.AmSerialChart1();
    chart.dataProvider = data;
    chart.categoryField = "title";
    chart.startDuration = 1;

    // AXES
    // category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.labelRotation = 0; // this line makes category values to be rotated
    categoryAxis.gridAlpha = 0;
    categoryAxis.fillAlpha = 1;
    categoryAxis.fillColor = "#FAFAFA";
    categoryAxis.gridPosition = "start";
    // value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.dashLength = 5;
    valueAxis.title = "";
    valueAxis.axisAlpha = 0;
    chart.addValueAxis(valueAxis);
    // GRAPH
    var graph = new AmCharts.AmGraph();
    graph.valueField = "num";
    graph.colorField = "color";
    graph.balloonText = "[[category]]: [[value]]";
    graph.type = "column";
    graph.lineAlpha = 0;
    graph.fillAlphas = 1;
    chart.addGraph(graph);
    // CURSOR
    var chartCursor = new AmCharts.ChartCursor();
    chartCursor.cursorAlpha = 0;
    chartCursor.zoomable = false;
    chartCursor.categoryBalloonEnabled = false;
    chart.addChartCursor(chartCursor);
    chart.creditsPosition = "top-right";
    // WRITE
    chart.write(objId);
}